package com.surfilter.code.util;

public class StringUtils {

	
	/**
	 * 将以"点"分隔的字符串转换为以"下划线"分隔的字符串
	 */
	public static String convertStringReplacePointToUnderline(String source){
		if(source == null || source.trim().equals("")){
			return "";
		}
		return source.replace(".", "_"); 
	}

	/**
	 * 将以"下划线"分隔的字符串转换为以"点"分隔的字符串
	 */
	public static String convertStringReplaceUnderlineToPoint(String source){
		if(source == null || source.trim().equals("")){
			return "";
		}
		return source.replace("_", "."); 
	}
	
	/**
	 * 将以"下划线"分隔的字符串转换为以"/"分隔的字符串
	 */
	public static String convertStringReplaceUnderlineToSplash(String source){
		if(source == null || source.trim().equals("")){
			return "";
		}
		return source.replace("_", "/"); 
	}
	
	/**
	 * 将以"点"分隔的字符串转换为以"/"分隔的字符串
	 */
	public static String convertStringReplacePointToSplash(String source){
		if(source == null || source.trim().equals("")){
			return "";
		}
		return source.replace(".", "/"); 
	}

	/**
	 * 将以"/"分隔的字符串转换为以"点"分隔的字符串
	 */
	public static String convertStringReplaceSplashToPoint(String source){
		if(source == null || source.trim().equals("")){
			return "";
		}
		return source.replace("/", "."); 
	}
	
	/**
	 * 首字母变大写，其余变小写
	 * @param moduleName
	 * @return
	 */
	public static String convertFirstCharUpperCap(String moduleName) {
		
		if(moduleName == null || moduleName.equals("")){
			return "";
		}
		if(moduleName.length() == 1){
			return moduleName.toUpperCase();
		}else{
			String first = moduleName.substring(0, 1);
			String leave = moduleName.substring(1);
			return first.toUpperCase() + leave.toLowerCase(); 
		}
	}

	/**
	 * 首字母变大写
	 * @param moduleName
	 * @return
	 */
	public static String convertFirstCharUpperCapOnly(String moduleName) {
		
		if(moduleName == null || moduleName.equals("")){
			return "";
		}
		if(moduleName.length() == 1){
			return moduleName.toUpperCase();
		}else{
			String first = moduleName.substring(0, 1);
			String leave = moduleName.substring(1);
			return first.toUpperCase() + leave; 
		}
	}
	
	/**
	 * 首字母变小写
	 * @param moduleName
	 * @return
	 */
	public static String convertFirstCharLowCap(String moduleName) {
		
		if(moduleName == null || moduleName.equals("")){
			return "";
		}
		if(moduleName.length() == 1){
			return moduleName.toLowerCase();
		}else{
			String first = moduleName.substring(0, 1);
			String leave = moduleName.substring(1);
			return first.toLowerCase() + leave; 
		}
	}
	
	/**
	 * 将表明转换为Class名
	 */
	public static String convertTableNameToClazzName(String tableName) {
		String[] subArray = tableName.split("_");
		StringBuffer midString = new StringBuffer();
		for(String subString : subArray){
			midString.append(convertFirstCharUpperCap(subString.toLowerCase()));
		}
		return midString.toString();
	}
	
	/**
	 * 将列转换为java Field名
	 */
	public static String convertColumNameToJavaFieldName(String columName) {
		
		String[] subArray = columName.split("_");
		StringBuffer midString = new StringBuffer();
		for(String subString : subArray){
			midString.append(convertFirstCharUpperCap(subString.toLowerCase()));
		}
		return convertFirstCharLowCap(midString.toString());
	}
	/**
	 * 把以.分隔的字符串分解成字符串数组
	 */
	public static String convertServiceClassToJsModuleName(String serviceClass) {
		
		String str = null;
		if(serviceClass.contains("/")) {
			String [] strs = serviceClass.split("/");
			str = strs[strs.length - 1];
		}
		if(serviceClass.contains(".")) {
			String [] strs = serviceClass.split("\\.");
			str = strs[strs.length - 1];
		}
		return str;
	}
	
	
}
